extends PropertyFindSetter


class_name DirectionSetter
"""
设置Vector2属性
"""


@export var force: float = 1
@export_range(-360, 360, 1, "radians_as_degrees") var angle: float = 0

@export_category("From")
@export var from_finder: INodeFinder = null
@export var to_finder: INodeFinder = null
@export_category("")


func __check_exports() -> Dictionary:
    return IComponent.merge({
        "to_finder": func(): return to_finder != null,
    }, super.__check_exports())

func __get_update_value(w: Object, p: String) -> Variant:
    var from: Node2D = from_finder.find() as Node2D
    var to: Node2D = to_finder.find() as Node2D
    if from == null or to == null:
        return null
    var p1: Vector2 = from.global_position
    var p2: Vector2 = to.global_position
    var d: Vector2 = (p2 - p1).normalized() * force
    if not is_zero_approx(angle):
        d = d.rotated(angle)
    return d
